package com.ruoyi.demo.controller.test;

import cn.hutool.core.util.RandomUtil;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.rabbitmq.client.RabbitMqClient;
import com.ruoyi.rabbitmq.constant.DelayedConstant;
import com.ruoyi.rabbitmq.constant.GeneralConstant;
import com.ruoyi.rabbitmq.utils.BaseMap;
import com.ruoyi.rabbitmq.utils.MqConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbitmq")
public class RabbitTestController {

    @Autowired
    RabbitMqClient rabbitMqClient;

    /**
     * 发送消息 绑定默认交换机
     *
     * @return
     */
    @GetMapping("/test")
    public R test() {
        //rabbitmq消息队列测试
        BaseMap map = new BaseMap();
        map.put("orderId", RandomUtil.randomNumbers(10));
        rabbitMqClient.sendMessage(MqConstant.MQ_RUOYI_MQ, map);//即时
        rabbitMqClient.sendMessage(MqConstant.MQ_RUOYI_MQ_TIME, map, 10);//延时10S
        return R.ok();
    }

    /**
     * 发送消息 绑定自定义交换机
     *
     * @return
     */
    @GetMapping("/2/test")
    public R test2() {
        //rabbitmq消息队列测试
        String orderId = RandomUtil.randomNumbers(10);
        rabbitMqClient.send(GeneralConstant.CustomTestConstant.CUSTOM_TEST_EXCHANGE, GeneralConstant.CustomTestConstant.CUSTOM_TEST_ROUTER, orderId);//即时
        rabbitMqClient.send(DelayedConstant.CustomTestDelayedConstant.CUSTOM_TEST_DELAYED_EXCHANGE, DelayedConstant.CustomTestDelayedConstant.CUSTOM_TEST_DELAYED_ROUTING, orderId, 10);//延时10S
        return R.ok();
    }
}
